<?php

use frontend\assets\AppAsset;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use common\models\Category;
use yii\helpers\Url;
use kartik\select2\Select2;

/* @var $this yii\web\View */
/* @var $searchModel common\models\WebsiteSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Websites');
$this->params['breadcrumbs'][] = $this->title;
?>
    <div class="website-index">
        <p>
            <?= Html::a(Yii::t('app', 'Create Category'), Url::to('/admin/index.php?r=/category/create'), ['class' => 'btn btn-success']) ?>

            <?= Html::a(Yii::t('app', 'Create Website'), Url::to('/admin/index.php?r=/website/create'), ['class' => 'btn btn-success']) ?>
        </p>
        <?php Pjax::begin(); ?>    <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [
//                ['class' => 'yii\grid\SerialColumn'],

                [
                    'attribute' => 'category_id',
                    'value' => function ($model) {
                        return $model->category->name;
                    },
                    'filter' => Category::select2($searchModel->category_id, 'WebsiteSearch[category_id]'),
                ],
                [
                    'attribute' => 'title',
                    'value' => function ($model) {
                        return Html::a($model->title,
                            $model->url,
                            [
                                'target' => '_blank',
                                'data-pjax' => 0,
                                'onclick' => 'jump(' . $model->id . ');'
                            ]);
                    },
                    'format' => 'raw',
                ],
//                [
//                    'attribute' => 'desc',
//                    'value' => function ($model) {
//                        return '<p title="' . $model->desc . '">' . substr($model->desc, 0, 120) . '</p>';
//                    },
//                    'format' => 'raw',
//                    'filter' => true,
//                ],
//
//                [
//                    'attribute' => 'page_view',
//                    'filter' => false,
//                ],
//                [
//                    'attribute' => 'create_at',
//                    'filter' => false,
//                    'format' => 'datetime',
//                ],
//                [
//                    'attribute' => 'update_at',
//                    'filter' => false,
//                    'format' => 'datetime',
//                ],
            ],
        ]); ?>
        <?php Pjax::end(); ?></div>
<?php

AppAsset::register($this);
$this->registerJsFile('/js/select2/dist/js/select2.js', ['depends' => ['frontend\assets\AppAsset']]);
$this->registerCssFile('/js/select2/dist/css/select2.css', ['depends' => ['frontend\assets\AppAsset']]);
?>